home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1998 June / Software of the Month Club 1998 June.iso / pc / dos / dtp / vde / vmacro.ref < prev    next >
Text File  |  1998-04-15  |  47KB  |  817 lines

  1.  
  2.                                   VMACRO.REF
  3.                                   ----------
  4.                      Macro Reference for the VDE Editor:
  5.                          version 1.85 (21 Jan 1998)
  6.  
  7.                              (c)1987-98, E. Meyer
  8.  
  9.  
  10.  
  11.  ===============================  CONTENTS  ==================================
  12.  
  13.  
  14.      9. CREATING MACROS:
  15.           A. Keystrokes and notation
  16.           B. Defining macros
  17.           C. Recording macros
  18.           D. Assigning macros to keys
  19.           E. Macro programming
  20.           F. Examples of useful macros
  21.           G. Adding features: Mail Merge
  22.  
  23.     10. MACRO REFERENCE, alphabetically by topic:
  24.           Autoexec macro, Chaining and calling, Counter variable, Define or 
  25.           record macro, Error handling, Function keys, Function key labels, 
  26.           Key definition files, Labels and jumps, Pause or user input, Prompt 
  27.           automation, Sorting, Tests and loops, Toggle control, Value 
  28.           adjustment.
  29.  
  30.      See also:
  31.           VDE.DOC    - QUICK START, SYNTAX, TECHNICAL INFORMATION, etc.
  32.           VDE.REF    - comprehensive COMMAND REFERENCE
  33.           VINST.REF  - use of the VINST installation utility
  34.  
  35.  
  36.  
  37.  ==========================  9. CREATING MACROS  =============================
  38.  
  39.                           A. KEYSTROKES AND NOTATION
  40.  
  41.      Essentially, a macro is a sequence of keystrokes representing text and/or 
  42.  VDE commands, which can then be repeated automatically or stored to a key for 
  43.  future use in order to make frequently performed tasks easier.
  44.  
  45.      While this may sound quite straightforward, it's obviously necessary to 
  46.  get such a key sequence EXACTLY correct for the macro to perform as intended; 
  47.  therefore, the representations of macros in this manual present many 
  48.  possibilities for confusion.  First, some basics: the characters "[]" are 
  49.  often used to signify the pressing of a single key, like "[Esc]" -- but they 
  50.  aren't used when that key is exhibited as part of a macro or multi-key 
  51.  command, like "Esc&F2".  Also, don't be confused by the fact that a single 
  52.  bracket can also appear as part of certain macro commands, like "Esc~^M]".  
  53.  The character "^" is normally used to indicate control-key combinations, as 
  54.  in "^M" for Ctrl-M; but there are special cases when the character "^" itself 
  55.  needs to be typed, as in "Esc&^F2" or "^K^".
  56.  
  57.      A space will often be used here to separate groups of keystrokes to make 
  58.  a macro easier to read and understand -- but these spaces ARE NOT part of the 
  59.  macro, and should not be typed in when trying to define it.  Any spaces that 
  60.  actually ARE part of the macro and SHOULD be typed in are represented by the 
  61.  underline character "_", which is not itself part of any macro here.
  62.  
  63.      Finally, there are occasional differences between the keystrokes you 
  64.  would actually type in order to perform a task, and those that must be typed 
  65.  in order to enter this sequence at the macro definition prompt.  At all VDE 
  66.  string prompts, certain keys control the entering of the string itself; for 
  67.  the macro definition command ^M, this is a somewhat shorter list than for 
  68.  other PROMPTS, but it still includes:
  69.            [Enter], ^[Enter] -- macro definition complete
  70.         [<],[>],[BkSp],[Del] -- correct/edit characters entered
  71.                           ^R -- (as 1st key) replay the last macro entered
  72.                           ^P -- enter codes like these in macro
  73.  This means that to include any of these keys AS PART OF THE MACRO ITSELF 
  74.  requires the ^P prefix first (except for [>] and [Del] when the cursor is at 
  75.  the end of the input line).  If you forget this prefix, of course, the key 
  76.  will instead perform its function indicated above.
  77.      Throughout this manual, macros are presented as they actually function, 
  78.  since this is easier to understand; that is, they DO NOT include any extra ^P 
  79.  prefixes required for code entry.  If you're trying to enter a macro at the 
  80.  definition prompt, you must remember to use caution with the above control 
  81.  keys!  (See also ^P NESTING, below.)
  82.      It is also important to bear in mind that starting with VDE 1.8, the 
  83.  following keys are no longer equivalent for most purposes:
  84.            [Enter] and ^M (CR)    [BkSp] and ^H     [Esc] and ^[
  85.           ^[Enter] and ^J (LF)    [Tab]  and ^I
  86.  The one case where these keys remain interchangeable is in their use after ^P 
  87.  to embed an ASCII control-code (like ^H, ASCII 08) in the text.  Otherwise, 
  88.  they are related but distinct: [BkSp] is a COMMAND that deletes a character 
  89.  from the text or a prompt input line, while ^H (BS) is a CHARACTER that can 
  90.  be part of the text (where it will cause a backspace when printing); ^H can 
  91.  also be an entirely unrelated COMMAND itself.  [BkSp] will require a ^P 
  92.  prefix to enter into a macro, ^H will not; and so on.  (Any macros from VDE 
  93.  versions prior to 1.8 will need to be redefined with these differences in 
  94.  mind.)
  95.  
  96.      EXAMPLE: Consider the following macro, whose purpose is explained more 
  97.  fully below under EXAMPLES OF USEFUL MACROS:
  98.  
  99.                    ^QS ^X Esc=_] Esc=^M] ^S_^D Esc![
  100.  
  101.  Following the explanations above, be sure you understand why in the middle of 
  102.  defining this macro you must use ^M, not [Enter], and verify that it will 
  103.  involve 17 separate keystrokes, namely:
  104.  
  105.        Macro:  Ctrl-Q S Ctrl-X Esc = Space ] Esc = Ctrl-M ]
  106.                    Ctrl-S Space Ctrl-D Esc ! [
  107.  
  108.  and then, of course, a final [Enter] to terminate the definition.  If you do 
  109.  this correctly, you'll see on screen something like this (the underlined 
  110.  letters will be highlighted as control-codes, and the "e" symbol indicating 
  111.  the [Esc] key is actually an epsilon):
  112.  
  113.        Macro:  QSXe= ]e=M]S De![
  114.                - --   - - - --
  115.  
  116.  
  117.  ---------------------------- B. DEFINING MACROS -----------------------------
  118.  
  119.  
  120.      To DEFINE a Macro, press ^M.  Macros execute EXACTLY as though you had 
  121.  typed the given keys yourself; this means that every keystroke, including 
  122.  answers to prompts, [Enter]s, and so on, must be properly included, so plan 
  123.  ahead carefully, with pen and paper if necessary.
  124.      Any PC keys can be entered at this prompt; a few, like arrow keys, will 
  125.  display with a recognizable symbol, but most (PgUp, etc) will simply show as 
  126.  a highlighted asterisk "*".  (VINST is capable of displaying the full 
  127.  keynames, if you create or display macros with it instead.)  Even MenuBar 
  128.  selections (except {User:...}) can be used in macros, with the ^[Esc] command 
  129.  (see MENUBARS).
  130.      Since the macro prompt accepts [Esc] without a ^P-prefix, it can't be 
  131.  used to abandon the definition; you can only do so by pressing ^[Break], or 
  132.  [Enter] followed by [Esc] at the next prompt.
  133.  
  134.      You can end a macro definition by pressing ^[Enter], to bypass the 
  135.  options below: VDE will simply repeat your macro (visibly) until you press 
  136.  [Esc] to stop it.  Otherwise, if you press [Enter], VDE will ask whether you 
  137.  want to Use it immediately or store it (on storing, see ASSIGNING MACROS TO 
  138.  KEYS).  If you're going to use it now, you need to decide whether you want 
  139.  the macro to repeat (and if so, how many times), and whether you want to 
  140.  watch it happen.
  141.             VDE asks "Make Quiet, No-repeat, Both?"  Reply "Q" for 
  142.          Quiet (fast) operation, or press [Enter] for visible 
  143.          (slower) execution.  (The "N/B" options are intended for 
  144.          storing to keys, but can also be typed here to skip the 
  145.          next question.)
  146.             VDE asks "Repeat count?"  Type the number of times to 
  147.          execute (0-254), or just [Enter] for 1; or "*" to repeat 
  148.          indefinitely.
  149.  
  150.      When a macro is executing, the "!" flag appears in the header; normally, 
  151.  you can also see its effects as it proceeds.  You can cancel it at any time 
  152.  by pressing [Esc].  If you chose to speed up macro execution by specifying 
  153.  "Q"uiet mode, only the header will be updated as the macro runs.  (Don't do 
  154.  this if the macro uses any commands that require user input -- the necessary 
  155.  prompt would not display, and the macro would just appear to have stalled.)
  156.      By default, macros will stop automatically if an error condition occurs, 
  157.  in which case the error message will display briefly; or if the cursor 
  158.  attempts to move past the top or end of the file, in which case no error 
  159.  displays.  (See also ERROR HANDLING.)  Thus some macros will halt on their 
  160.  own when they reach the end of a file; others may have to be terminated 
  161.  manually, by pressing [Esc].
  162.  
  163.      Once defined, a macro can be recovered by typing ^R to replay it at the 
  164.  ^M prompt, so that you can choose to Use it again, or store it if you did not 
  165.  previously do so.  (You can also edit it first, if desired.)
  166.      ^F, when entered as part of an input string, normally inserts the name of 
  167.  the current file (see PROMPTS).  In a macro definition, it remains an ^F, 
  168.  expanded to the current filename only when the macro actually executes.  This 
  169.  can be useful to refer to the current file when running compilers and file 
  170.  utilities.  Thus, if you define the macro
  171.                      AltR compile_^F_/g_/r1 [Enter] [Esc]
  172.  the ^F embedded in the string will be expanded, so that the DOS command 
  173.  executed by AltR when the macro is invoked will actually be something like
  174.                      compile C:\PGM\MYPROG.C /g /r1.
  175.  Note: if the file is untitled, ^F causes an error that halts the macro.
  176.      Similarly, ^[, which inserts text from a block at a prompt, remains ^[ in 
  177.  a macro definition, inserting the block text only when the macro actually 
  178.  executes.  This useful feature makes it possible for a macro to search for 
  179.  further occurrences of whatever text is at the cursor, etc.
  180.  
  181.  
  182.      EXAMPLES OF ^P NESTING.  Note that in some situations, the use of ^P as a 
  183.  prefix for control keys at the macro definition prompt becomes nested.  
  184.  Suppose you want to define a macro containing the word "counterrevolutionary" 
  185.  with "counter" italicized.  The keystrokes you'd use yourself are:
  186.                      ^P^Ycounter^P^Yrevolutionary
  187.  but to get these into a macro definition, you must type ^P TWICE to enter 
  188.  each ^P; ^P^Y by itself will enter only the ^Y into the macro, which would 
  189.  delete a line!  So you'll type:
  190.               Macro: ...^PP^Ycounter^PP^Yrevolutionary...
  191.      Or, suppose you want to find the next occurrence of "Item" at the 
  192.  beginning of a line.  The actual keystrokes needed are:
  193.                      ^QF^MItem^[Enter]
  194.  (Note the use of ^[Enter] instead of [Enter] to avoid the Options prompt.)  
  195.  But to enter this as part of a macro definition, you'll have to type:
  196.               Macro: ...^QF^MItem^P^[Enter]...
  197.      Failure to nest ^P prefixes properly is one of the most common causes of 
  198.  unexpected macro behavior.
  199.  
  200.      TECHNICAL NOTE: Ordinarily macros are completely self-contained, and 
  201.  NEVER request input from the keyboard while executing (unless the input pause 
  202.  commands Esc? or Esc: are used).  Confirmation prompts like "Abandon changes 
  203.  (Y/N)?", which may or may not pop up in normal usage of commands affecting 
  204.  disk files, NEVER occur when a macro is running, so you should never try to 
  205.  include a confirming "Y".  But there is one exception: using AltR to run 
  206.  another program (or DOS shell) from a macro is tricky.  Any input requested 
  207.  by the program or shell must be typed by you -- it cannot be included in the 
  208.  macro.  VDE resumes control only when the program or shell terminates; if the 
  209.  macro continues, its next keystroke must be the [Esc] required to return to 
  210.  editing.
  211.  
  212.  
  213.  --------------------------- C. RECORDING MACROS -----------------------------
  214.  
  215.  
  216.      As an alternative to composing macros and using the ^M command to define 
  217.  them, you can simply record a macro as you go about a task.  The main 
  218.  advantages are that you can see the effects as you go, and none of the 
  219.  additional ^P keystrokes sometimes necessary for entering commands at the 
  220.  macro definition prompt will be needed.  (On the other hand, a recorded macro 
  221.  must be a simple series of keystrokes; it cannot contain programming commands 
  222.  like jumps and tests.)
  223.  
  224.      Just press ^M^M (that is, ^M again at the Macro prompt) to activate 
  225.  recording; type away; and press ^M again to conclude.  You will then be asked 
  226.  whether to use or store the macro you have created, just as if you had 
  227.  entered the macro at the prompt.  (You can even recall it with ^R the next 
  228.  time you use the ^M command.)
  229.      While recording, a quote mark (") will be visible in the upper right 
  230.  (prefix) area of the header.  If you make a mistake, use ^M again to stop 
  231.  recording, press [Esc] at the prompt to quit, and start over.  If anything 
  232.  you do while recording results in an error condition, recording will be 
  233.  canceled, and the quote will disappear from the header.
  234.  
  235.  
  236.      NOTES: Because Function key commands (and also the {User:} MenuBar) use 
  237.  the same internal processes as macros, they cannot be used while macro 
  238.  recording is in progress.  Any other keystrokes can be recorded, including 
  239.  all other MenuBar selections.  Although they may not always be usefully 
  240.  precise, even mouse movements can be recorded as part of a macro, because 
  241.  they are simulated internally as sequences of arrow keys.
  242.  
  243.  
  244.  ----------------------- D. ASSIGNING MACROS TO KEYS -------------------------
  245.  
  246.  
  247.      Macros can be assigned to function keys, and then recalled and used with 
  248.  one keystroke.  Each PC function key can be used alone or with Shift (often 
  249.  indicated by VDE as "!"), Ctrl ("^"), or Alt ("@"), to produce 48 different 
  250.  macro keys.  VDE comes with [F1] set as "Help" (^J) and [F10] as "Menu" 
  251.  (^Esc), but this can be changed.
  252.      If you find function keys difficult to remember, you can also assign a 
  253.  mnemonic letter or digit (alias) to invoke a definition with the [Esc] key; 
  254.  thus, if your Address is on ^[F3], you could also call it up with EscA.
  255.  
  256.      The ^M command (see MACRO DEFINITION) gives the option of storing the 
  257.  macro definition to any function key, so that the macro can later be executed 
  258.  simply by pressing that key.  Instead of selecting "U"se, press the desired 
  259.  key, from [F1] to @[F12].  Then:
  260.             VDE asks "Make Quiet, No-repeat, Both:".  Reply "Q" for 
  261.          a key that executes in Quiet (fast) mode; "N" for a key 
  262.          that runs once, without asking for a repeat count; or "B" 
  263.          for both of these.  Just press [Enter] for neither -- a key 
  264.          that executes just like the "Use" option, visibly, asking 
  265.          for a repeat count first.
  266.             VDE asks "Esc key:".  If desired, you can choose a 
  267.          letter or digit to press after [Esc] as an alternate way of 
  268.          invoking this macro.
  269.             VDE asks "Label?".  You may enter a label, up to 7 
  270.          characters, for the label line (see FUNCTION KEY LABELS).
  271.  
  272.      Don't choose "Q"uiet (or "B"oth) for a key that will request input from 
  273.  you.  About 2000 bytes of storage are available for all 48 keys, and a 125- 
  274.  byte limit applies [in VDE; VINST can accept 253] to any one key.  You can 
  275.  delete an existing key definition by entering a null definition (^M, [Enter]) 
  276.  and storing it to the key.
  277.      Keys defined while editing in VDE last only during the current editing 
  278.  session.  [To add a function key permanently to VDE.EXE, use VINST: either 
  279.  enter it again in VINST, or write it to a file and read the file into VINST 
  280.  -- see DEFAULT FUNCTION KEYS and DATA FILES.]
  281.  
  282.  
  283.  --------------------------- E. MACRO PROGRAMMING ----------------------------
  284.  
  285.  
  286.      "Macro programming" refers to a group of VDE commands that operate only 
  287.  within a macro definition, and give you conditional control over the 
  288.  execution of a macro.  Thus, instead of simply running straight through a 
  289.  sequence of keystrokes, a macro can be constructed very much like a computer 
  290.  program, with conditional or unconditional jumps from one part of the macro 
  291.  to another, giving great flexibility and power.  Here is a brief introduction 
  292.  to the range of macro programming commands.
  293.  
  294.      Jumps require "labels" to identify a location to jump to: a macro label 
  295.  consists of [Esc] followed by a letter A-Z or digit 0-9.  If you typed this 
  296.  from the keyboard, it would be interpreted as an attempt to invoke a function 
  297.  key definition by an alias (see FUNCTION KEYS) -- but a macro can't do this, 
  298.  so EscA simply marks a location in the macro.
  299.  
  300.      Esc! is the unconditional jump instruction.  Followed by A-Z or 0-9, it 
  301.  causes execution of the macro to transfer to the command following that 
  302.  label, instead of simply continuing as usual to the next command.  So, for 
  303.  example, Esc!1 jumps to the label Esc1.  Thus the macro:
  304.  
  305.               This_is_ Esc!1 not_ Esc1 a_silly_macro.
  306.  
  307.  would produce the text "This is a silly macro."  In contrast, the macro:
  308.  
  309.               This_is_ Esc1 not_ Esc!1 a_silly_macro.
  310.  
  311.  would produce "This is not not not not not not not not not....", continuing 
  312.  indefinitely until you press [Esc] to abort it.  (This is an example of what 
  313.  programmers call an "infinite loop" -- occasionally useful, but generally an 
  314.  unfortunate error!)
  315.      There are also two special predefined "labels": "[" indicates the 
  316.  beginning of the macro, and "]" the end.  Thus Esc![ can be used to repeat 
  317.  the macro from the start, and Esc!] can be used to terminate it from any 
  318.  point.
  319.  
  320.      Several commands allow the use of a counter variable.  Esc() sets the 
  321.  value: for example, Esc(0) initializes it to zero.  The Esc+ command simply 
  322.  increments the value; Esc- (minus) is a conditional jump, decrementing the 
  323.  value, then jumping if it's zero to the specified label.  (In addition to a 
  324.  label 0-Z, you may use "[" or "]", or "@" to avoid jumping entirely.)  
  325.  Examples: Esc-] decrements the counter, jumping to the end (exiting) if it 
  326.  reaches zero; Esc-@ simply decrements it, with no jump.  Thus the macro:
  327.  
  328.               This_is_a_ Esc(3) EscL silly_ Esc-X Esc!L EscX macro.
  329.  
  330.  will produce the text "This is a silly silly silly macro."
  331.  
  332.      Conditional jumps, or tests, are performed by Esc= and Esc~.  Followed by 
  333.  a character, then a label, they are conditional jumps: they jump IF the text 
  334.  character at the cursor does (or for "~", does NOT) match the one specified.  
  335.  Examples: Esc~_2 jumps to label 2 if the cursor character is NOT a space; 
  336.  Esc=^M] jumps to the end (terminates) if the cursor character is a CR (^M).
  337.      Similarly, Esc< and Esc> test the cursor character's ASCII value and act 
  338.  accordingly: thus Esc<A2 jumps to label 2 if the cursor character value is 
  339.  less than ASCII "A" (41 hex), etc.
  340.  
  341.      The test commands (Esc=,~,<,>) can also be used in a second way, as self- 
  342.  contained search loops.  If instead of a label you use the character ">" or 
  343.  "<", the command will move the cursor right (or for "<", left) as long as the 
  344.  character at the cursor does (or for "~", does NOT) match the one specified.  
  345.  Example: Esc=_> moves right as long as the current character is a space (so 
  346.  it stops on the first NONspace).  Of course you could have done the same 
  347.  thing by programming an actual loop, with labels and a test and a right arrow 
  348.  command:
  349.               Esc1 Esc~_2 ^D Esc!1 Esc2
  350.  
  351.  but Esc=_> is simpler and more convenient.
  352.  
  353.       It is possible for one macro to chain (jump) to, or call, another macro.  
  354.  This can permit construction of a single macro longer than the usual maximum 
  355.  size; also, it often simply allows you to organize macros more efficiently 
  356.  and conserve definition space.  Esc&, followed by a key identification like 
  357.  "!F1", is used to chain to another key; the macro terminates when that key 
  358.  finishes.  Esc&& works similarly, but calls the other key, so that when it 
  359.  finishes, control returns to the original macro at the point following the 
  360.  Esc&& command.
  361.  
  362.  
  363.  ----------------------- F. EXAMPLES OF USEFUL MACROS ------------------------
  364.  
  365.  
  366.      Remember that macro examples are given as they function, NOT including 
  367.  the occasional ^P prefix you'll need to enter certain keys; and that while 
  368.  keystrokes are often separated by spaces for clarity, the underline symbol 
  369.  "_" is used to represent an actual space that you must type.
  370.      Many of the macro definitions in this section are included in the macro 
  371.  definition file EXAMPLES.VDF, which can be loaded with AltU.  (For details, 
  372.  see DEFAULT FUNCTION KEYS in VINST.REF.)
  373.  
  374.  
  375.                             SIMPLE MACRO EXAMPLES
  376.  
  377.      1. At its simplest, a function key is a way to reproduce keystrokes.  
  378.  Thus, if you're writing a document that will refer to "World Wide Widgets 
  379.  Ltd. (N.A.)" dozens of times, it will be easier (and cause fewer typos) if 
  380.  you define this phrase as a macro and assign it to a function key like [F3].
  381.  
  382.      2. The macro repeat count is an easy way to repeat VDE commands.  Suppose 
  383.  you have a horizontal bar installed as graphic character "Y", and you need to 
  384.  enter a line of 70 of them.  You could press AltG, then Y, 70 times... or you 
  385.  could define the macro:          AltG Y
  386.  and then Use it with a repeat count of 70.
  387.      Similarly, to reformat an entire file, go to the top if necessary, then 
  388.  use a macro to repeat the reformat command ^B: just end with ^[Enter] to 
  389.  proceed visibly, or go on to specify Quiet and indefinite repeat ("Q,*") for 
  390.  the fastest operation (it will stop at the end of the file).
  391.  
  392.      3. To view a file by scrolling slowly through it, use the macro:
  393.                           Esc; ^Z   or    Esc; ^C
  394.  This pauses, then scrolls down (a line at a time with ^Z, a screen at a time 
  395.  with ^C).  Don't make it Quiet, just repeat indefinitely (with ^[Enter] or a 
  396.  count of "*"); it will terminate when ^C reaches the end of the file, or when 
  397.  you press [Esc].
  398.  
  399.      4. This macro, with repeat count "*", would take all phrases in square 
  400.  brackets "[]" found in a file, and make a list of them in a second file being 
  401.  edited concurrently:
  402.      ^QR ^QF[^[Enter] ^G ^KB ^QF]^[Enter] ^G ^KK AltC AltN AltP [Enter] AltB
  403.  
  404.  
  405.                          SIMPLE FUNCTION KEY EXAMPLES
  406.  
  407.      1. This macro, which could be stored as No-repeat on a function key, re- 
  408.  loads the current file, eliminating any changes made since it was last saved:
  409.                                ^KL ^F [Enter]
  410.  
  411.      2. A function key defined as ^QR ^N AltD ^OF would place the current date 
  412.  at the top right of a letter.  Many VDE users set up a function key to 
  413.  produce a personalized letterhead: for example, the macro
  414.             ^N John_Doe ^OC ^N 123_Main_St ^OC ^N City,_State ^OC
  415.  will insert that three-line address, neatly centered.  You can add print 
  416.  effects (bold, italic) to suit your taste.  For a solid line separating this 
  417.  from the body of the letter, try adding onto the end:  ^N ^PS ^OF ^E ^PS ^X
  418.  
  419.      3. Function keys can be used to create powerful new commands, for 
  420.  example: ^D ^A ^KB ^F ^KK marks the current word as a block.  And, similarly, 
  421.  ^QS ^KB ^X ^KK marks the current line as a block.
  422.  
  423.  
  424.                           MACRO PROGRAMMING EXAMPLES
  425.  
  426.      1. This macro moves to the start of the current paragraph, by continuing 
  427.  to move back through the file until it finds a line that doesn't end with a 
  428.  space (soft CR):          ^QS ^S^S Esc=_[ ^D^D
  429.  Like the rest of the examples in this section, it might best be stored Quiet, 
  430.  No-Repeat to a function key.
  431.  
  432.      2. Moving to the start of the current sentence is a bit more complicated, 
  433.  but here is a macro program to do it, with some commentary:
  434.          Esc~.1 ^S                ;move left if already on period
  435.          Esc1 Esc~.<              ;move left to previous period
  436.          ^D Esc=_2 Esc=^M2        ;accept if followed by space or return,
  437.          ^S^S Esc!1               ; otherwise ignore and continue left
  438.          Esc2 ^D Esc=_2 Esc=^M2   ;move right over any space/returns
  439.                                   ; to start of sentence
  440.  
  441.      3. If you want to produce a "pure ASCII" file for software that can't 
  442.  accept control codes (other than CR,LF) or IBM graphics, here is a macro that 
  443.  will filter these out before you save to disk (use file modes /A,U,N):
  444.          Esc*f ^QR                ;formatting off, go to top of file
  445.          EscB Esc>~X              ;delete anything above "~" (graphics)
  446.          Esc=^MN                  ;accept CRLF
  447.          Esc<_X                   ;but delete anything below " " (ctrls)
  448.          EscN ^D Esc!B            ;(accept)
  449.          EscX ^G Esc!B            ;(delete)
  450.  The macro will terminate when it attempts to move beyond the end of the file.
  451.  
  452.      4.  Here is a macro that will eliminate unwanted blank lines from a file; 
  453.  every sequence of up to 10 blank lines will be reduced to just one, by 
  454.  repeated use of find/replace:
  455.     Esc$$ Esc(10) Esc1 ^QA ^M^M^M [Enter] ^M^M [Enter] GN [Enter] Esc-] Esc!1
  456.  
  457.      5. This macro moves the cursor to the center of the current line, using 
  458.  the counter variable to figure the line length, then move back only halfway:
  459.          ^QS Esc(0)               ;start at left, zero counter
  460.          Esc1 Esc+ ^D             ;loop: move right, increment counter
  461.          Esc~^M1                  ; (until you come to the CRLF)
  462.          Esc2 Esc-] Esc-] ^S      ;loop: move left, decrementing count TWICE
  463.          Esc!2                    ; (macro ends when it goes to zero)
  464.  
  465.      6. This macro counts and reports how many times the word at the cursor 
  466.  occurs in the file:
  467.         Esc1 ^S Esc>@<            ;move left to beginning of word
  468.         Esc='1 Esc=-1             ; (across letters or apostrophe/dash)
  469.         ^D^KB Esc<A]              ;mark start, quit if not letter
  470.         Esc2 ^D Esc>@>            ;move right to end of word
  471.         Esc='2 Esc=-2 ^KK         ; and mark it as block
  472.  Note that you can stop here, and you have a macro that simply marks the word 
  473.  at the cursor as a block.  But we continue:
  474.         Esc(0)                    ;zero counter
  475.         ^QF^[ [Enter]GCW[Enter]   ;find string (error if not found at all)
  476.         Esc$E Esc3 Esc+ ^L Esc!3  ;count and find each occurrence
  477.         EscE ^QB^KH Esc(H)        ;return to word, unmark, and report count
  478.  ^[ brings the marked word into the ^QF prompt; Esc(H) shows the count in the 
  479.  header when finished (don't run this Quiet, or you won't see it).
  480.  
  481.      7. Many programming languages use nested sets of parentheses, for example 
  482.  "{}" in C.  This macro, when the cursor is placed on an open bracket "{", 
  483.  will move ahead to find the closed bracket "}" that matches it:
  484.          Esc~{] Esc(0)            ;must be on bracket now; zero counter
  485.          Esc1 Esc~{2 Esc+ Esc!3   ;increment for every "{" encountered
  486.          Esc2 Esc~}3 Esc-]        ;decrement for every "}", quit when zero
  487.          Esc3 ^D Esc!1            ;keep moving along
  488.  
  489.      8. Here is a macro program using the Esc@ function (see SORTING below) in 
  490.  a very simple algorithm to arrange the lines of a file in alphabetical order 
  491.  by their first characters:
  492.          ^QC^QS^E                     ;start on last line of file
  493.          Esc1 Esc$E ^QS^E^KB          ;main loop: set error jump for cleanup,
  494.            ^QS^X^KK Esc$3             ;  mark previous line
  495.          Esc2 Esc@3 ^QS^X Esc!2       ;sort loop: find its place
  496.          Esc3 ^KV ^QP Esc!1           ;put it there, return to its position
  497.          EscE ^KH                     ;done, remove markers
  498.  This is reasonably fast when stored Quiet to a function key.  Different 
  499.  approaches could have been taken here; this macro works by building its 
  500.  sorted list from the bottom of the file up (to run faster if the file is 
  501.  already partially ordered).  The Esc@ test is applied repeatedly to find 
  502.  where each new line goes; ^QP returns to the top of the sorted section, to 
  503.  continue.  Esc$3 ensures that if the ^X hits the end of the text, the macro 
  504.  won't terminate but the line will just be put there.  Esc$E ensures that when 
  505.  the ^E hits the top of the text, the macro cleans up and exits gracefully.
  506.      You can use block zoom (^KZ) to sort only a portion of a file, or 
  507.  experiment with variations on this macro to sort in reverse order; on fields 
  508.  other than column 1; with multiline records; etc.
  509.  
  510.  
  511.  ---------------------- G. ADDING FEATURES: MAIL MERGE -----------------------
  512.  
  513.  
  514.      Many extra features commonly included in larger word processing packages 
  515.  aren't built into VDE.  But as the above examples have shown, macro 
  516.  programming and function keys actually allow you to develop your own custom 
  517.  editor commands, using the existing ones as building blocks.  This means that 
  518.  with macros you can often add features you need yourself, and moreover design 
  519.  them to work exactly the way you want!
  520.  
  521.      To demonstrate that this isn't really difficult at all, consider "Mail 
  522.  Merge": the automatic production of multiple copies of the same document, 
  523.  with occasional insertions at certain points taken from a data list.  The 
  524.  classic example is a form letter to be sent to dozens, or hundreds, of 
  525.  recipients on a mailing list.  Suppose we compose the text of our letter -- 
  526.  except that in place of a name (since they'll vary) we'll just type a 
  527.  variable name, say "@@N", instead, and in place of an address, the variable 
  528.  "@@A".  So the file might begin:
  529.                                              29 February 1993
  530.               @@N
  531.               @@A
  532.  
  533.               Dear @@N,
  534.  
  535.                    We are pleased to announce the opening of...
  536.  
  537.  And in another file we have our mailing list, possibly typed by hand, more 
  538.  likely generated by a database program.  Various formats are possible; let's 
  539.  suppose that each "entry" is a name and address, of varying numbers of lines, 
  540.  terminated by an empty line.  So the file might begin:
  541.  
  542.               C.J. Aubergine              <- first line of file
  543.               221-A Slumgullion Road
  544.               Hoagie, IL 63213
  545.                                           <- blank line after each entry
  546.               Margarita Empanada
  547.               P.O. Box 3172
  548.               Sopapilla, CA 91306
  549.  
  550.               Karl Hasenpfeffer
  551.               Schlagsahnestr. 11
  552.               D-1380 Rotkohl
  553.               GERMANY
  554.  
  555.      You'd like to have a key like [F12] programmed so that you could just 
  556.  press it in order to print off a whole series of letters, one for each entry 
  557.  in the list, with the appropriate information in the header and salutation.  
  558.  You can probably see how you'd go about the job yourself manually, though it 
  559.  would be incredibly tedious: find each "@@" variable in the letter file, 
  560.  switch to the data list, mark and cut the name (for @@N) or address (for 
  561.  @@N), paste it into the letter file in place of the variable name, print the 
  562.  letter when done, then start all over again with the second name...  Thus, 
  563.  one approach to creating a mail-merge macro would be to switch on macro 
  564.  recording while creating the first letter to print yourself -- ending your 
  565.  recorded key sequence by reloading the original letter with the variable 
  566.  names and advancing to the second entry in the list, ready to continue.  Then 
  567.  you could store the resulting macro to a key, and execute it repeatedly.
  568.  
  569.      Alternatively, you could plan everything out ahead of time and design a 
  570.  macro program containing appropriate labels and jumps to execute the entire 
  571.  process automatically.  The following macro will work properly with files as 
  572.  described above; just install it (No-repeat) on a function key.  Brief 
  573.  comments have been added for explanation.  Before using the macro as 
  574.  presented here, you must be editing the letter file (which must have been 
  575.  saved to disk), with the address list loaded as a second file, and the cursor 
  576.  must be at the top of both files.  If you want to test it out without wasting 
  577.  paper, use a spooler utility to redirect your printer output to a disk file, 
  578.  or substitute Esc; or Esc? for the ^KP[Enter] command so you can view each 
  579.  version of the letter on screen as it's finished.  It's rather striking how 
  580.  much can be accomplished with such a modest macro.
  581.  
  582.    Esc$3 ^QF@@^[Enter]           ;Find next variable, skip to print if none
  583.    Esc$$ ^D^D Esc=A1 Esc~N[      ;Was it @@A or @@N? (skip if neither)
  584.    AltN ^KB^QD^KK AltC           ;Request was for Name,
  585.    ^QS AltN Esc!2                ; so mark and cut first line of entry
  586.      Esc1                        ;  (always leaving cursor at start of entry)
  587.    AltN ^X^KB^QF^M^M^[Enter] ^KK ;Request was for Address,
  588.    AltC ^QB^E AltN               ; so mark and cut the rest of the entry
  589.      Esc2
  590.    ^A^G^G^G                      ;Back to the letter: delete variable name,
  591.    AltP Esc![                    ; paste in the data, and go on to next
  592.      Esc3
  593.    ^KP[Enter]                    ;Letter is ready, so print it
  594.    ^KL^F[Enter]                  ; and reload original copy with @@ variables
  595.    AltN ^QF^M^M^[Enter] ^D^D     ;Position to next entry in list
  596.    Esc<_]                        ;Quit if no more entries,
  597.    AltN Esc![                    ; otherwise do it all over again
  598.  
  599.      You will find this macro program available for use in the EXAMPLES.VDF 
  600.  file (see DEFAULT FUNCTION KEYS in VINST.REF).  This example has been kept
  601.  very simple, to illustrate the basic approach; as an exercise, you might try 
  602.  modifying it to put only the first name in the letter salutation, or to use 
  603.  database lists in comma-delimited format, and so on.  You can tailor your own 
  604.  mail-merge feature to suit your requirements.
  605.  
  606.  
  607.  ==========================  10. MACRO REFERENCE  ============================
  608.  
  609.  
  610.  AUTOEXEC MACRO -  VINST can designate one function key definition you create 
  611.     as "autoexec", meaning that this macro will execute automatically whenever 
  612.     you first enter VDE.  This feature can be used in a variety of ways, for 
  613.     example:
  614.               (1) You can use an autoexec macro to change defaults 
  615.          not available as VINST options.  (If you load multiple 
  616.          files, remember that some settings like margins are 
  617.          specific to each file, so only the first file will be 
  618.          affected.)
  619.               (2) You can turn VDE into a text modification engine 
  620.          by setting up a key definition (.VDF) file containing an 
  621.          autoexec macro program that alters the text in some way and 
  622.          then exits.  (Any .VDF file specified with a ";" on the 
  623.          command line is loaded before the autoexec process.)
  624.     See also SYNTAX, FUNCTION KEYS, DATA FILES.  (Note: if an autoexec macro 
  625.     exists, you cannot use a utility that stuffs input into the DOS keyboard 
  626.     buffer before running VDE.)
  627.  
  628.  CHAINING AND CALLING (Esc&,&&) -  Esc&, followed by a key identification like 
  629.     "!F1", is used to "chain" (or jump) to another function key.  Use "!,^,@" 
  630.     for Shift, Ctrl, Alt; and after the "F", a single digit "1"-"9", or "A"- 
  631.     "C" for 10-12.  ("0" is also accepted for F10.)  Examples: Esc&F2 chains 
  632.     to F2; Esc&^FB chains to Ctrl-F11.
  633.          Esc&& works similarly but "calls" the other key, returning when it 
  634.     finishes.  Calls may be nested at most 4 deep.
  635.  
  636.  COUNTER VARIABLE (Esc(),+,-) -  Esc(n) sets the counter value to "n".  Esc+ 
  637.     simply increments the value; Esc- (minus) is a conditional jump, decre- 
  638.     menting the counter, then jumping if it's zero to a specified label.  
  639.     (Besides a label 0-Z, you can use "[" or "]" for the start or end, or "@" 
  640.     to decrement without jumping at all.)
  641.          The counter can effectively run "negative", though it's actually an 
  642.     unsigned integer: if you decrement it from 0, it becomes 65535 then 65534 
  643.     (for -1, -2); if you increment it from 65535, it becomes 0.  It is not 
  644.     reset after a macro runs, and can be passed to another macro later.
  645.          Two special commands can also be used with the counter value:
  646.       Esc(T) - write counter value into Text at cursor position
  647.       Esc(H) - display counter value briefly in Header
  648.  
  649.  DEFINE OR RECORD MACRO (^M,^M^M) -  To define a macro, press ^M.  You will be 
  650.     asked for the macro definition; for full instructions, see DEFINING 
  651.     MACROS.  You can end with ^[Enter] to repeat the macro immediately, or 
  652.     [Enter] to proceed to choose whether to Use the macro or to store it to an 
  653.     F-key, and how.
  654.          Even if you didn't store your last macro when you originally defined 
  655.     it, you can still edit, re-use or store it subsequently by using ^R 
  656.     (replay) at the ^M prompt.
  657.          As an alternative to composing macros and using the ^M command to 
  658.     type them in, you can simply record a macro as you go about a task.  Press 
  659.     ^M TWICE (that is, a second time at the Macro prompt) to activate 
  660.     recording; type away; then press ^M again to conclude.  While recording, a 
  661.     quote mark (") will be visible in the upper right (prefix) area of the 
  662.     header.  If you make an error while recording, use ^M to stop recording, 
  663.     press [Esc] at the resulting prompt to quit, and start over.
  664.  
  665.  ERROR HANDLING (Esc$) -  Esc$ can specify a label where macro execution 
  666.     should continue if an error occurs (normally, execution would terminate).  
  667.     Thus, after the command Esc$E, any command resulting in an error (like 
  668.     "Not Found") will cause a jump to label E, ignoring the error.  You can 
  669.     also use the special characters "[","]" to jump to the beginning or end of 
  670.     the macro, or "@" to simply ignore errors, not jumping anywhere, or "$" to 
  671.     return to the normal default of halting on any error.
  672.  
  673.  FUNCTION KEYS ([F1]...[F12], EscA-Z,0-9) -  Macros can be assigned to 
  674.     function keys, either alone or with Shift, Ctrl, or Alt (!,^,@) for a 
  675.     total of 48 function keys.  These keys can be labeled for easy remembering 
  676.     (see FUNCTION KEY LABELS), or you can assign a letter or digit to invoke a 
  677.     definition with the [Esc] key; thus, if your Address is on ^[F3], you 
  678.     could also call it up with (say) EscA.  For detailed instructions, see 
  679.     ASSIGNING MACROS TO KEYS.
  680.          (Note: users of VDE prior to version 1.7 will recall EscA-Z as a 
  681.     separately definable set of macro keys; they now function simply as 
  682.     mnemonic aliases for function keys.)
  683.  
  684.  FUNCTION KEY LABELS (^OU) -  To help you remember the purpose of your 
  685.     function key definitions, the ^OU command toggles the display of a label 
  686.     line at the bottom of the screen.  When a key is defined, its number 
  687.     appears on the label line, followed by the label (if any) entered when the 
  688.     key was stored.
  689.          The label display is sensitive to keyboard shift status; if you press 
  690.     and hold Shift, Ctrl, or Alt for a moment, the labels will change to show 
  691.     those for the shifted function keys.
  692.          On 80-column screens, 10 labels are visible; in 40-column mode, 5.  
  693.     Labels for the [F11-12] keys only appear on screens of 96 or more columns.
  694.  
  695.  KEY DEFINITION FILES (AltU) -  These files save function key definitions and 
  696.     labels, and should be given a file type of ".VDF".  You can load such a 
  697.     file, along with your text file(s) to edit, from the command line (see 
  698.     SYNTAX).  You can also load or save .VDF files with the AltU command while 
  699.     editing (see DATA FILES).
  700.          [VINST can also create .VDF files or install them in your copy of 
  701.     VDE, and handle individual .VDK files; see DEFAULT FUNCTION KEYS.]
  702.  
  703.  LABELS AND JUMPS (Esc0..Z,Esc!) -  Esc0..Z, when placed in a macro, function 
  704.     simply as local "labels" 0..Z.  They have no effect, but can be "jumped" 
  705.     to by other commands.
  706.          Esc! followed by 0..9,A..Z is a "jump" instruction, causing macro 
  707.     execution to resume with the command following that label: for example, 
  708.     Esc!2 jumps to label 2 (Esc2).  As special cases, Esc![ jumps to the 
  709.     beginning of the macro, and Esc!] jumps to the end (exits).
  710.          Note that labels can also be referenced by the test commands, which 
  711.     perform conditional jumps (see TESTS AND LOOPS).
  712.  
  713.  PAUSE OR USER INPUT (Esc;,Esc?,Esc:) -  Esc; gives a brief pause before macro 
  714.     execution continues, so the user can see what's happening on screen.  Use 
  715.     two or more to get a longer pause.
  716.          Esc? accepts text or commands from the keyboard during macro 
  717.     execution.  The header's "!" flag turns into "?" when user input is 
  718.     expected.  Anything except macro and function key commands may be used.  
  719.     [Esc] terminates input, returning control to the macro.  ^[Break] aborts.
  720.          Esc: makes the following command take its input from the keyboard.  
  721.     The macro resumes when that command is completed.  Examples: Esc:^QF 
  722.     allows you to type in the string to find; Esc:Esc! actually lets you type 
  723.     the label to jump to.
  724.  
  725.  PROMPT AUTOMATION (^F,^[,^R) -  It's worth pointing out the usefulness of 
  726.     several of the control codes that operate at command prompts (see PROMPTS) 
  727.     for automating operation in macros.  ^F allows you to reference the 
  728.     current filename in VDE file commands, or even DOS commands run from AltR.  
  729.     ^[ provides the current block text as prompt input, allowing the use of 
  730.     commands like find/replace on whatever is there.  ^R replays whatever the 
  731.     previous input to this type of command (file, search, macro, etc) was.
  732.  
  733.  SORTING (Esc@) -  Esc@ is a essentially version of Esc< for entire strings, 
  734.     rather than individual characters: it performs a string comparison (with 
  735.     conditional jump) between text in a marked block and text at the cursor.  
  736.     As with Esc<, the comparison goes by ASCII values, essentially 
  737.     alphabetically; it proceeds character by character until a difference is 
  738.     found.  If the block string has a value less than or equal to the cursor 
  739.     string, which is to say that it could belong "at" (@) the cursor location, 
  740.     the jump is performed (possibly to code that will put it there); if 
  741.     greater, not (and one might move on down the list).
  742.          NOTES: Esc@ scans up to 24 characters, is case-insensitive, and 
  743.     treats accented letters in the ASCII 80-A5 range as their ordinary letter 
  744.     equivalents.
  745.          Rather than having one specific sorting command built into VDE, the 
  746.     Esc@ comparison can be used to implement any sorting method you require.  
  747.     For example, the macro program described under EXAMPLES above does the 
  748.     most common task, arranging the lines of a file alphabetically by their 
  749.     initial characters.  Many other variations can be imagined: reverse sort, 
  750.     sort on other fields, sort records of several lines, algorithms that might 
  751.     be faster in certain situations, etc.
  752.  
  753.  TESTS AND LOOPS (Esc=,~,<,>) -  Esc= and Esc~ perform tests on the character 
  754.     at the current cursor position.  They can be used in two ways:
  755.              (1) Followed by a character, then a label (0-Z,[,]), 
  756.          they are conditional jumps: they jump to the label IF the 
  757.          cursor character does (or for "~", does NOT) match the one 
  758.          specified.
  759.              (2) Followed by a character, then ">" or "<", they are 
  760.          search loops.  They will continue to move the cursor right 
  761.          or left as long as the cursor character does (or for "~", 
  762.          does NOT) match.
  763.     Similarly, Esc< and Esc> test the cursor character's ASCII value and act 
  764.     according to whether it's less, or greater, than the specified value.  
  765.     (See ASCII table in VINST.REF)
  766.          (Note: place and block markers, since they aren't text characters at 
  767.     all, will fail any test.  If you need to check for their presence, you can 
  768.     use Esc<^@ [that's 00 hex, entered as ^P@] since no actual character could 
  769.     be <0 and fail this test.)
  770.  
  771.  TOGGLE CONTROL (Esc*) -  "Toggle" commands can create difficulties when used 
  772.     in macro and function keys: ^V, for example, toggles insert mode.  But 
  773.     when you plan a function key, you don't necessarily know how Insert will 
  774.     be set when the key is used!  So if you use ^V in the macro, you don't 
  775.     know whether you just turned it off or on; you might be overstriking or 
  776.     inserting, and can't tell.
  777.          The Esc* command provides a solution, by letting a macro specify an 
  778.     exact state for each toggle.  Esc* must be followed by a LETTER to 
  779.     identify a toggle, UPPERcase to turn it ON or LOWERcase to turn it OFF.  
  780.     (A few options have a third state, as well.)  For example, Esc*i will set 
  781.     INSERT OFF, regardless of its previous state.  The toggles are:
  782.               Autoindent     (^OA)     'a'=off  'A'=on
  783.               Column block  (^KN,I)    'c'=off  'C'=on  'O'=replace
  784.               Doublespace    (^OS)     'd'=off  'D'=on
  785.               auto Format    (^OM)     'f'=off  'F'=on
  786.               Hyphenation    (^OH)     'h'=off  'H'=on
  787.               Insert         (^V)      'i'=off  'I'=on  'W'=word
  788.               Justification  (^OJ)     'j'=off  'J'=on  'R'=remove
  789.             * Load excluded files      'l'=off  'L'=on
  790.             * Match hard CRs exactly   'm'=off  'M'=on
  791.               Proportional   (^OK)     'p'=off  'P'=on
  792.             * Single line reformat     's'=off  'S'=on
  793.             * Trim spaces from nondocs 't'=off  'T'=on
  794.             * Unload speller from memory      'u,U'
  795.               Variable tabs  (^OV)     'v'=off  'V'=on
  796.               margin release (^OX)     'x'=off  'X'=on
  797.               hard reformat  (^OY)     'y'=off  'Y'=on
  798.     The cases marked "*" actually don't correspond to standard user commands; 
  799.     instead, they give access to some more of VDE's internal settings and 
  800.     defaults.  (Usage is described in the appropriate section of VDE.REF)
  801.  
  802.  VALUE ADJUSTMENT (Esc/) -  It can be very useful for a macro to adjust a 
  803.     value without having to know what it previously was: to indent both 
  804.     margins 10 columns, for example, whatever they were.  The Esc/ command 
  805.     makes this possible: it must be followed by a LETTER to identify the 
  806.     value, a NUMBER from 1 to 99, and finally a "+" or "-" sign.  The 
  807.     adjustments are:
  808.               Left margin    (^OL)     'L'
  809.               Right margin   (^OR)     'R'
  810.               Page length    (^OP)     'P'
  811.     Example: Esc/L10+ increases the left margin by 10 columns.  Like the Esc* 
  812.     toggles, these commands are primarily intended for, but not limited to, 
  813.     use in macros.
  814.  
  815.  
  816.  =============================[end VMACRO.REF]================================
  817.